package com.fary.resourcepath;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Enumeration;

public class TestResourcePath {


    /**
     * 获取资源文件
     */
    public static void main(String[] args) throws IOException {

        String path = "beans.xml";

        // 从classpath下查找该文件
        URL url = TestResourcePath.class.getResource("/" + path);

        // 从当前类的位置去查找
        URL url1 = TestResourcePath.class.getResource("");

		// 从classpath下查找该文件
        InputStream inputStream1 = TestResourcePath.class.getResourceAsStream("/" + path);

		// 从当前类的位置去查找
        InputStream inputStream2 = TestResourcePath.class.getResourceAsStream("TestResourcePath.class");


        InputStream inputStream3 = TestResourcePath.class.getClassLoader().getResourceAsStream(path);
		URL url2 = TestResourcePath.class.getClassLoader().getResource(path);
		Enumeration<URL> urlResources = TestResourcePath.class.getClassLoader().getResources(path);

        InputStream inputStream4 = ClassLoader.getSystemResourceAsStream(path);
		URL url3 = ClassLoader.getSystemResource(path);
		Enumeration<URL> urlResources2 = ClassLoader.getSystemResources(path);

        System.out.println();
    }


}
